const app = getApp()
var module=require("../../../utils/jinbo/huodongricheng.js");
var url=app.globalData.url;
Page({
  data: {
    page:0,
    companies:null,
  	language:'',
    imageUrl:app.globalData.imageUrl,
    inputShowed: false,
    inputVal: "",
    countrySelected: false,
    countryShowed: false,
    country: null,
    typeSelected: false,
    typeShowed: false,
    type: null,
    current:'',
    currentActivityId:0,
    currentChoose:null,
    day:0,
    number:0,
  },
  onLoad: function () {
    var lang = app.globalData.lang;
    if (lang != "zh") {
      wx.setNavigationBarTitle({
        title: 'Agenda'
      })
    }
    this.setData({
      language:app.globalData.lang,
      currentChoose:module[lang].choose,
      // country:module[lang].country,
      type:module[lang].type
    });
    this.changeCompanies();
  },
  hideSelect: function (e) {
    this.setData({
      countrySelected: false,
      typeSelected: false,
      showRadio: false,
    });
  },
  checkDetail(e){
    this.setData({
      currentActivityId:this.data.currentActivityId==e.currentTarget.dataset.id?0:e.currentTarget.dataset.id
    });
  },
  selectTime(e){
      this.setData({
        day:Number(e.currentTarget.dataset.day),
        number:0
      });
      this.changeCompanies();
  },
  chooseRadioItem:function(e){
    const index=e.currentTarget.dataset.index;
    if(this.data.current=='country'){
      this.data.currentChoose.country.title=this.data.country[Number(index)].title;
      this.data.currentChoose.country.id=this.data.country[Number(index)].id;    
    }else{
      this.data.currentChoose.type.title=this.data.type[Number(index)].title;
      this.data.currentChoose.type.id=this.data.type[Number(index)].id;
    }
    this.setData({
      currentChoose: this.data.currentChoose,
      countrySelected: false,
      typeSelected: false,
      showRadio:false,
    });
    this.changeCompanies();
  },
  chooseCountry: function(e) {
    this.setData({
      current:'country',
      countrySelected: !this.data.countrySelected,
      typeSelected: false,
      showRadio:this.data.countrySelected?false:true,
    });
  },
  chooseType: function(e) {
    this.setData({
      current:'type',
      countrySelected: false,
      typeSelected: !this.data.typeSelected,
      showRadio:this.data.typeSelected?false:true,
    });
  },
  clearInput: function() {
    this.setData({
      inputVal: ""
    });
    this.changeCompanies();
  },
  inputTyping: function(e) {
    this.setData({
      inputVal: e.detail.value
    });
    this.changeCompanies();
  },
  changeCompanies:function(){
    var that=this;
    wx.showLoading({
      title:'正在加载...'
    });
    wx.request({
      url:app.globalData.url+'activity/showList',
      method:'POST',
      data:{
        country:this.data.currentChoose.country.id,
        type:this.data.currentChoose.type.id,
        day:this.data.day,
        language:this.data.language,
        title:this.data.inputVal,
        },
      success:function(res){
    if(res.data.code==1){
      that.setData({
        companies:res.data.data.companies,
        country:res.data.data.country,
      },function(){
        wx.hideLoading();
      }); 
    }else if(res.data.code==0){
      wx.showToast({
            title:res.data.msg,
            icon:"none"
          });
    }
      }
    });
  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    var that = this;
    return {
      title: app.globalData.shareTitle,
      path: app.globalData.sharePath,
      imageUrl: '../../../images/share_img.png',
      success: function (res) {
        // 转发成功
      },
      fail: function (res) {
        // 转发失败
      }
    }
  },
})